/**
 * Created by Administrator on 2016/1/7.
 */
//展示界面的socket
var showId = "index";
//控制界面的socket
var controlId = "control";
//保存socket关系的map
var socketMap = {};

var http = require('http');

var tools = {
    //获取显示端socket
    getIndex:function(){
        return   socketMap[showId];
    },
    init:function(app){
        var tools = this;
        http.Server(app);
        var io = require('socket.io')(http).listen(5000);
        //监听连接事件
        io.on('connection', function(socket){
            console.log("connection");
            //设置页面的socketID
            socket.on("login", function(data){
                socket.loginId = data.id;
                socketMap[data.id] = socket;
                //返回登录后是否在线的信息
                socket.emit("login", {event:"login",message:"连接成功"});
            });
            socket.on('disconnect', function(socket){
                console.log("disconnect")
            });
        });
    }
};

module.exports = tools;